package com.music.server.controller;


import com.music.server.pojo.Song;
import com.music.server.pojo.SongList;
import com.music.server.service.SongListService;
import com.music.server.utils.ResultVo;
import com.music.server.vo.SongListVo;
import com.music.server.vo.SongVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 歌单 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-03-08
 */
@RestController
@RequestMapping("songList")
public class SongListController {

    @Autowired
    private SongListService songListService;

    /**
     * 添加歌单信息
     * @return
     */
    @PostMapping("save")
    public ResultVo save(@RequestBody SongList songList){
        boolean save = songListService.save(songList);
        if (save) return ResultVo.ok();
        return ResultVo.error();
    }

    /**
     * 修改歌单信息
     * @return
     */
    @PutMapping("update")
    public ResultVo update(@RequestBody  SongList songList){
        boolean update = songListService.updateById(songList);
        if (update) return ResultVo.ok();
        return ResultVo.error();
    }

    /**
     * 查询所有的歌单信息
     * @return
     */
    @GetMapping("list")
    public ResultVo list(){
        List<SongList> list = songListService.list();
        return ResultVo.ok().data("list",list);
    }


    /**
     * 分页条件查询所有的歌单信息
     * @return
     */
    @PostMapping("page/{pageNum}/{size}")
    public ResultVo page(@PathVariable Integer pageNum,@PathVariable Integer size,@RequestBody SongListVo songListVo){

        return ResultVo.ok().data("page",songListService.page(pageNum,size,songListVo));
    }


    /**
     * 删除歌单信息及对应的所有信息
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public ResultVo delete(@PathVariable Integer id){
        boolean delete = songListService.deleteById(id);
        if (delete) return ResultVo.ok();
        return ResultVo.error();
    }

}

